import request from './request'
import { useUserStore } from '../store/modules/user'
import { AxiosPromise } from 'axios'
/**
 *
 * @param data 知识中心分类接口 - 新增或修改知识库分类
 * @returns
 */
export function knowledgeTypeSave(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/type/save',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 知识中心分类接口 - 获取知识库分类列表
 * @param data
 * @returns
 */
export function getKnowledgeTypeList(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/type/getList',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 知识中心分类接口 - 根据知识库分类ID获取详情
 * @param id
 * @returns
 */
export function getKnowledgeTypeDetail(id: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/knowledge/type/${id}`,
    method: 'GET',
    headers: token,
  })
}

/**
 * 知识中心分类接口 - 批量启用或禁用知识库分类
 * @param status 知识库分类状态：false-启用，true-禁用
 * @param data 知识库分类ID数组
 * @returns
 */
export function updateKnowledgeTypeDisable(status: boolean, data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/knowledge/type/disable?status=${status}`,
    method: 'PUT',
    headers: token,
    data,
  })
}

/**
 * 知识中心分类接口 - 批量删除知识库分类
 * @param data 知识库分类ID数组
 * @returns
 */
export function deleteKnowledgeType(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/knowledge/type/delete`,
    method: 'DELETE',
    headers: token,
    data,
  })
}

/**
 * 知识中心类下拉接口 - 知识库分类下拉数据列表
 * @param data
 * @returns
 */
export function knowledgeTypepageSelect(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/knowledge/select/knowledgeTypepageSelect`,
    method: 'POST',
    headers: token,
    data,
  })
}

/**
 * 获取说明书列表
 * @param {Object} data - 请求参数
 * @param {String} data.name - 搜索关键字
 * @param {Number} data.limit - 一页显示多少条
 * @param {Number} data.page - 页码
 */
export function instrList(data: {
  name: string
  limit: number
  page: number
}): AxiosPromise<KnownAPIResponse.ManualList> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/instruction-book/getList',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 新增或修改说明书
 * @param {KnownAPIRequest.ManualForm} data - 请求参数
 */
export function instrSave(data: KnownAPIRequest.ManualForm): AxiosPromise<APIResponse> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/instruction-book/save',
    method: 'post',
    headers: token,
    data: data,
  })
}

/**
 * 获取说明书信息
 * @param {String} id - 说明书id
 */
export function instrInfo(id: string): AxiosPromise<KnownAPIResponse.ManualInfo> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/instruction-book/' + id,
    method: 'get',
    headers: token,
  })
}

/**
 * 批量启用或禁用说明书
 * @param {Array<string>} ids - 说明书id集合
 * @param {Boolean} status - 状态：false-启用，true-禁用
 */
export function instrDisable(ids: Array<string>, status: boolean): AxiosPromise<APIResponse> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/instruction-book/disable',
    method: 'put',
    headers: token,
    data: ids,
    params: { status },
  })
}

/**
 * 批量删除说明书
 * @param {Array<string>} data - 说明书id集合
 */
export function instrDelete(data: Array<string>): AxiosPromise<APIResponse> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/instruction-book/',
    method: 'delete',
    headers: token,
    data,
  })
}

/**
 * 获取视频列表
 * @param {Object} data - 请求参数
 * @param {String} data.name - 搜索关键字
 * @param {Number} data.page - 页码
 * @param {Number} data.limit - 一页显示多少条
 */
export function getVideoList(data: {
  name: string
  page: number
  limit: number
}): AxiosPromise<KnownAPIResponse.VideoList> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/video/getList',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 新增或修改视频
 * @param {KnownAPIRequest.VideoForm} data - 请求参数
 */
export function videoSave(data: KnownAPIRequest.VideoForm): AxiosPromise<APIResponse> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/video/save',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 获取视频信息
 * @param {String} id - 视频id
 */
export function videoInfo(id: string): AxiosPromise<KnownAPIResponse.VideoInfo> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/video/' + id,
    method: 'get',
    headers: token,
  })
}

/**
 * 批量启用或禁用视频
 * @param {Array<string>} ids - 视频id集合
 * @param {Boolean} status - 状态：false-启用，true-禁用
 */
export function videoDisable(ids: Array<string>, status: boolean): AxiosPromise<APIResponse> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/video/disable',
    method: 'put',
    headers: token,
    data: ids,
    params: { status: status },
  })
}

/**
 * 批量删除视频
 * @param {Array<string>} ids - 视频id集合
 */
export function videoDelete(ids: Array<string>): AxiosPromise<APIResponse> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/video/',
    method: 'delete',
    headers: token,
    data: ids,
  })
}

// 获取故障列表
export function gteFaultList(
  data: KnownAPIRequest.KnownFaultList,
): AxiosPromise<KnownAPIResponse.Faults> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/fault/getList',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 新增或修改故障
 * @param {KnownAPIRequest.KnownFaultAdd} data - 请求参数
 */
export function saveFault(data: KnownAPIRequest.KnownFaultAdd): AxiosPromise<APIResponse> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/fault/save',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 获取故障详情
 * @param {String} id - 故障id
 */
export function detailFault(id: string): AxiosPromise<KnownAPIResponse.FaultDetail> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/fault/' + id,
    method: 'get',
    headers: token,
  })
}

// 批量启用或禁用故障
export function disableFault(data: Array<string>, status: boolean): AxiosPromise<APIResponse> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/fault/disable',
    method: 'put',
    headers: token,
    data,
    params: { status },
  })
}

// 批量启用或禁用故障
export function deleteFault(data: Array<string>): AxiosPromise<APIResponse> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/fault/',
    method: 'delete',
    headers: token,
    data,
  })
}

/**
 * 故障分类保存
 * @param {KnownAPIRequest.KnowFaultTypeSave} data - 故障分类对象
 */
export const faultTypeSave = (
  data: KnownAPIRequest.KnowFaultTypeSave,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/fault/type/save',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 获取故障分类
 */
export const getFaultTypes = (): AxiosPromise<KnownAPIResponse.FaultTypes> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/fault/type/getList',
    method: 'post',
    headers: token,
  })
}

/**
 * 获取故障分类详情
 * @param {string} id - 故障分类id
 */
export const getFaultTypeDetailById = (
  id: string,
): AxiosPromise<KnownAPIResponse.FaultTypeDetail> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/fault/type/${id}`,
    method: 'get',
    headers: token,
  })
}

/**
 * 批量删除故障分类
 * @param {Array<string>} ids - 故障分类id集合
 */
export const faultTypesDel = (ids: Array<string>): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/fault/type/delete',
    method: 'delete',
    headers: token,
    data: ids,
  })
}

/**
 * 批量禁用/启用故障分类
 * @param {Array<string>} ids - 故障分类id集合
 * @param {Boolean} status - 启用/禁用
 */
export const faultTypesUpdateStatus = (
  ids: Array<string>,
  status: boolean,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/fault/type/disable',
    method: 'put',
    headers: token,
    data: ids,
    params: { status },
  })
}

/**
 * 批量移动端显示/隐藏
 * @param {Array<string>} ids - 故障id集合
 * @param {Boolean} mobileShow - false：启用，true：禁用
 */
export const faultsMobileDisable = (
  ids: Array<string>,
  mobileShow: boolean,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/fault/updateMobileShow',
    method: 'post',
    headers: token,
    data: ids,
    params: { mobileShow },
  })
}

/**
 * 批量开启/关闭报表分析
 * @param {Array<string>} ids - 故障id集合
 * @param {Boolean} reportAnalysis - 是否开启报表分析-true：开启，false：关闭
 */
export const faultsUpdateReportAnalysisStatus = (
  ids: Array<string>,
  reportAnalysis: boolean,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/fault/updateReportAnalysis',
    method: 'post',
    headers: token,
    data: ids,
    params: { reportAnalysis },
  })
}

/**
 * 批量更新可见类型
 * @param {Array<string>} ids - 故障id集合
 * @param {1 | 2 | 3} visibilityType - 可见类型
 */
export const faultsUpdateVisibleType = (
  ids: Array<string>,
  visibilityType: 1 | 2 | 3,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/fault/updateVisibilityType',
    method: 'post',
    headers: token,
    data: ids,
    params: { visibilityType },
  })
}

/**
 * 获取故障库下拉
 * @param {Object} data - 请求参数
 * @param {Number} data.limit - 一页显示多少条
 * @param {Number} data.page - 当前页码
 * @param {String} data.name - 搜索关键字
 */
export const getFaultOptions = (data: {
  limit: number
  page: number
  name: string
}): AxiosPromise<KnownAPIResponse.FaultOptions> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/select/getFaultSelect',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 根据故障分类获取故障库
 * @param {Array<KnownAPIRequest.GetFaultByType>} data - 请求参数
 */
export const getFaultByType = (
  data: Array<KnownAPIRequest.GetFaultByType>,
): AxiosPromise<KnownAPIResponse.FaultListByType> => {
  return request({
    url: '/knowledge/select/getFaultByFaultType',
    method: 'post',
    data,
  })
}
